//⾯试题 17.19. 消失的两个数字
class Solution {
    public int[] missingTwo(int[] nums) {
        // 1. 先把所有的数异或在⼀起
        int tmp = 0;
        for (int x : nums)
            tmp ^= x;
        for (int i = 1; i <= nums.length + 2; i++)
            tmp ^= i;
        // 2. 找出 a，b 两个数⽐特位不同的那⼀位
        int diff = 0;
        while (true) {
            if (((tmp >> diff) & 1) == 1)
                break;
            else
                diff++;
        }
        // 3. 将所有的数按照 diff 位不同，分两类异或
        int[] ret = new int[2];
        for (int x : nums)
            if (((x >> diff) & 1) == 1)
                ret[1] ^= x;
            else
                ret[0] ^= x;
        for (int i = 1; i <= nums.length + 2; i++)
            if (((i >> diff) & 1) == 1)
                ret[1] ^= i;
            else
                ret[0] ^= i;
        return ret;
    }
}